package org.linlinjava.litemall.wx.web;

import com.xxl.sso.core.conf.Conf;
import com.xxl.sso.core.user.XxlSsoUser;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LitemallBrand;
import org.linlinjava.litemall.db.domain.LitemallTenderQuote;
import org.linlinjava.litemall.db.service.LitemallBrandService;
import org.linlinjava.litemall.db.service.LitemallTenderQuoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @description:
 * @program: mall
 * @author: youvy
 * @create: 2019-12-27 15:12
 **/
@RestController
@RequestMapping("tenderQuote")
public class WxTenderQuoteController {
	@Autowired
	private LitemallTenderQuoteService tenderQuoteService;
	@Autowired
	private LitemallBrandService brandService;

	@PostMapping("/wxList")
	public Object wxList(@RequestBody String json, HttpServletRequest request) {
		Integer page = JacksonUtil.parseInteger(json, "page");
		Integer pageSize = JacksonUtil.parseInteger(json, "pageSize");
		Integer tenderId = JacksonUtil.parseInteger(json, "id");

		List<LitemallTenderQuote> list = tenderQuoteService.list(page, pageSize, null,1,tenderId);
		for (LitemallTenderQuote litemallTenderQuote : list) {
			LitemallBrand brand = brandService.findById(litemallTenderQuote.getBrandId());
			litemallTenderQuote.setBrandName(brand.getName());
		}
		return ResponseUtil.okList(list);

	}

/*	@PostMapping("/brand/brandList")
	public Object brandList(@RequestBody String json) {
		Integer page = JacksonUtil.parseInteger(json, "page");
		Integer pageSize = JacksonUtil.parseInteger(json, "pageSize");
		String statusStr = JacksonUtil.parseString(json, "status");
		Integer status = null;
		if (statusStr!=null){
			status=Integer.parseInt(statusStr);
		}

		List<LitemallTenderQuote> list = tenderQuoteService.list(page, pageSize, null, null,status);
		return ResponseUtil.okList(list);

	}*/

	@PostMapping("/brand/insert")
	public Object insert(@RequestBody LitemallTenderQuote tender,HttpServletRequest request) {
		XxlSsoUser user = (XxlSsoUser) (request.getAttribute(Conf.SSO_USER));
		tenderQuoteService.insert(tender);
		return ResponseUtil.ok();
	}

	@PostMapping("/brand/update")
	public Object update(@RequestBody LitemallTenderQuote tender) {
		tenderQuoteService.update(tender);
		return ResponseUtil.ok();
	}

	@PostMapping("/brand/delete")
	public Object delete(@RequestBody String json) {
		Integer id = JacksonUtil.parseInteger(json, "id");
		tenderQuoteService.delete(id);
		return ResponseUtil.ok();
	}

}
